import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/core/utils/user_manager.dart';
import 'package:enterprise_v6_app/app/data/api/auth_apis.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';
import 'package:get/get.dart';

class InitController extends GetxController {
  @override
  void onInit() {
    super.onInit();
    init();
  }

  init() async {
    // Interface.mainBaseUrl = 'http://203.25.213.22:30014'; //正式服
    final res = await AuthApis.getUrl().execute();
    // 成功后
    res.onSuccess((value) async {
      Interface.mainBaseUrl = value.data!.gsPaMainApiUrl!;
      // 外网测试地址
      // Interface.mainBaseUrl = 'http://api.huiyi.yifan.link:32000';
      // Interface.mainBaseUrl = 'http://117.173.150.167:32000';

      /// 文件上传地址
      Interface.fileUrl = value.data!.gsFileUrl!;

      Interface.mapUrl = value.data!.threeDimensionalMap ?? '';

      Interface.workUrl = value.data!.jobTicketAddress ?? '';

      Interface.faceAuthUrl = value.data!.faceIdentify ?? '';

      if (value.data!.pullAddress != null) {
        Interface.pullUrl = '${value.data!.pullAddress!}/ai_live/';
      }

      if (value.data!.pushAddress != null) {
        Interface.rtmpUrl = '${value.data!.pushAddress!}/live';
      }

      await Future.delayed(const Duration(milliseconds: 500));
      // Interface.rtmpUrl = 'rtmp://192.168.10.247:1935/live/';
      // 如果没有登录，跳转登录
      if (!UserManager.isLoggedIn) {
        Get.offAndToNamed(AppRoutes.authLogin);
      } else {
        Get.offAndToNamed(AppRoutes.home);
      }
    });
  }
}
